package com.ruoyi.cderp.service.impl;

import java.util.List;

import com.ruoyi.cderp.mapper.MaterialMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cderp.mapper.MaterialStockMapper;
import com.ruoyi.cderp.domain.MaterialStock;
import com.ruoyi.cderp.service.IMaterialStockService;

/**
 * 物料库存Service业务层处理
 * 
 * @author wzy
 * @date 2025-06-09
 */
@Service
public class MaterialStockServiceImpl implements IMaterialStockService 
{
    @Autowired
    private MaterialStockMapper materialStockMapper;
    @Autowired
    private MaterialMapper materialMapper;

    /**
     * 查询物料库存
     * 
     * @param id 物料库存主键
     * @return 物料库存
     */
    @Override
    public MaterialStock selectMaterialStockById(String id)
    {
        MaterialStock materialStock=materialStockMapper.selectMaterialStockById(id);
        materialStock.setMaterial(materialMapper.selectMaterialById(materialStock.getMaterialId()));

        return materialStock;
    }

    /**
     * 查询物料库存列表
     * 
     * @param materialStock 物料库存
     * @return 物料库存
     */
    @Override
    public List<MaterialStock> selectMaterialStockList(MaterialStock materialStock)
    {
        List<MaterialStock> list=materialStockMapper.selectMaterialStockList(materialStock);
        for (MaterialStock str:list){
            str.setMaterial(materialMapper.selectMaterialById(str.getMaterialId()));
        }
        return list;
    }

    /**
     * 新增物料库存
     * 
     * @param materialStock 物料库存
     * @return 结果
     */
    @Override
    public int insertMaterialStock(MaterialStock materialStock)
    {
        materialStock.setCreateTime(DateUtils.getNowDate());
        return materialStockMapper.insertMaterialStock(materialStock);
    }

    /**
     * 修改物料库存
     * 
     * @param materialStock 物料库存
     * @return 结果
     */
    @Override
    public int updateMaterialStock(MaterialStock materialStock)
    {
        materialStock.setUpdateTime(DateUtils.getNowDate());
        return materialStockMapper.updateMaterialStock(materialStock);
    }

    /**
     * 批量删除物料库存
     * 
     * @param ids 需要删除的物料库存主键
     * @return 结果
     */
    @Override
    public int deleteMaterialStockByIds(String[] ids)
    {
        return materialStockMapper.deleteMaterialStockByIds(ids);
    }

    /**
     * 删除物料库存信息
     * 
     * @param id 物料库存主键
     * @return 结果
     */
    @Override
    public int deleteMaterialStockById(String id)
    {
        return materialStockMapper.deleteMaterialStockById(id);
    }
}
